<template>
	<view>
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input  :adjust-position="false" type="number"
				 :placeholder="placeholder" confirm-type="search"
				 maxlength="13" @input="handleInput"></input>
				 <text class="cuIcon-scan" style="margin-right: 26rpx; transform: scale(1.2);" @click="handleScan"></text>
			</view>
			<view class="action">
				<button  @click="handleTap" class="cu-btn bg-yellow text-white text-bold shadow-blur round">搜 索</button>
			</view>
		</view>
		
	</view>
</template>

<script>
	var _self;
	import {handleSearch} from '../../request/handleReq.js';
	export default {
		name:'mySearch',
		data() {
			return {
				input:''
			};
		},
		
		props:{
			placeholder:{
				type:String,
				default:''
			}
		},
		
		methods:{
			handleTap(){
				
				_self.$emit('getInput',_self.input);
				
				
			},
			
			handleInput(e){
				_self.input = e.detail.value;
				
			},
			
			 handleScan(){
				uni.scanCode({
				    onlyFromCamera:true,
				    scanType:['barCode'],
				    success:async (result) => {
						// console.log(result);
						const res = await handleSearch(result.result);
						// console.log(res);
						uni.navigateTo({
							url: '/pages/book_details/book_details?book='+encodeURIComponent(JSON.stringify(res))
						});
				
	
				    }
				});
			}
		},
		
		mounted() {
			_self = this;
		}
		
		
		
	}
</script>

<style>

</style>
